Introduction
This R Markdown report enables to analyze time series from Yahoo Finance of userâs choice. The report takes user input and creates tables, plots and tests based on that input and allows to thoroughly analyze different quotes and time spans without interfering with the code.
This version of report provides several tech and motor companies to choose from, however, should one want to analyze another, he/she should add the abbreviation and companyâs full name to the parameterâs choice list and dictionary and the report would be good to go. Default time range spans back a thousand days from the day of running the report. Should the multiple choice for the quotes be left empty, then as default, all prices are included in the analysis. Last parameter determines the forecast period in days.
Data
Gathering of the time series data is performed via getSymbols function provided in quantmod package. More information about the package can be found here. Data used in this particular report is characterized by following parameters:
- Company name:
Apple Inc. - Company abbreviation:
AAPL - Time span:
2021-03-29-2021-06-01 - Quotes:
Low, Close - Simulation paths:
10
Below you can see a glimpse of the first and last few observations of the data of your choice.
| Date | AAPL.Low | AAPL.Close |
|---|---|---|
| 2021-05-28 | 124.55 | 124.61 |
| 2021-05-27 | 125.08 | 125.28 |
| 2021-05-26 | 126.42 | 126.85 |
| 2021-05-25 | 126.32 | 126.90 |
| 2021-05-24 | 125.94 | 127.10 |
| 2021-05-21 | 125.21 | 125.43 |
| Date | AAPL.Low | AAPL.Close |
|---|---|---|
| 2021-04-06 | 125.65 | 126.21 |
| 2021-04-05 | 123.07 | 125.90 |
| 2021-04-01 | 122.49 | 123.00 |
| 2021-03-31 | 121.15 | 122.15 |
| 2021-03-30 | 118.86 | 119.90 |
| 2021-03-29 | 120.73 | 121.39 |
Descriptive statistics
General
Below you can find a handful of descriptive statistics regarding the columns specified during knitting. Maximum price recorded for Apple Inc. during 2021-03-29 - 2021-06-01 period was $134.84, while the minimum was $4.15. Number of observations between the periods is equal to 44.
| Variable | Mean | Std. | Min | 1st quartile | Median | 3rd quartile | Max |
|---|---|---|---|---|---|---|---|
| AAPL.Low | 127.66 | 4.15 | 118.86 | 125.01 | 126.75 | 131.70 | 134.11 |
| AAPL.Close | 128.80 | 4.23 | 119.90 | 125.78 | 127.88 | 133.03 | 134.84 |
Log returns
This chapter provides insight on the log returns of selected prices. Log returns are more widely used in finance than simple returns for a number of reasons, one being that prices are assumed to be log-normally distributed. That is not always the case as can be seen on the graphs below. Nevertheless, this assumption results in logarithms of prices to be normally distributed. More information on this topic can be found here.
Each of the graphs below represents a histogram of log returns of certain price, as well as kernel density estimate (white line). It is plotted agains a normal distribution (red line) with mean and standard deviation calculated separately for each graph.
AAPL.Low
AAPL.Close
Plotting
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
Stationarity analysis
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
Trend
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression trend
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + tt + z.diff.lag)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.9673 -0.8155 0.0528 0.9259 2.5893
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.93095 0.60096 1.549 0.12987
## z.lag.1 -0.99103 0.23912 -4.144 0.00019 ***
## tt -0.03856 0.02394 -1.611 0.11573
## z.diff.lag -0.08178 0.15775 -0.518 0.60724
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.68 on 37 degrees of freedom
## Multiple R-squared: 0.5489, Adjusted R-squared: 0.5123
## F-statistic: 15 on 3 and 37 DF, p-value: 1.507e-06
##
##
## Value of test-statistic is: -4.1445 5.7455 8.5908
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau3 -4.15 -3.50 -3.18
## phi2 7.02 5.13 4.31
## phi3 9.31 6.73 5.61
According to the ADF test the series are integrated of order 1, or in other words have become stationary after 1 differentiation(s). The program differentiated the series until it found order where value of test-statistic: -4.1444584 is smaller than tau3 5pct: -3.5.
Drift
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression drift
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 + 1 + z.diff.lag)
##
## Residuals:
## Min 1Q Median 3Q Max
## -5.0039 -0.6813 0.1793 1.0913 2.9578
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 0.06163 0.26984 0.228 0.820577
## z.lag.1 -0.84750 0.22651 -3.742 0.000603 ***
## z.diff.lag -0.14187 0.15646 -0.907 0.370257
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.715 on 38 degrees of freedom
## Multiple R-squared: 0.5172, Adjusted R-squared: 0.4918
## F-statistic: 20.36 on 2 and 38 DF, p-value: 9.8e-07
##
##
## Value of test-statistic is: -3.7416 7.0262
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau2 -3.58 -2.93 -2.60
## phi1 7.06 4.86 3.94
According to the ADF test the series are integrated of order 1, or in other words have become stationary after 1 differentiation(s). The program differentiated the series until it found order where value of test-statistic: -3.7416081 is smaller than tau3 5pct: -2.93.
None
##
## ###############################################
## # Augmented Dickey-Fuller Test Unit Root Test #
## ###############################################
##
## Test regression none
##
##
## Call:
## lm(formula = z.diff ~ z.lag.1 - 1 + z.diff.lag)
##
## Residuals:
## Min 1Q Median 3Q Max
## -4.9407 -0.6300 0.2296 1.1462 3.0134
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## z.lag.1 -0.8412 0.2221 -3.788 0.000513 ***
## z.diff.lag -0.1449 0.1540 -0.941 0.352643
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 1.694 on 39 degrees of freedom
## Multiple R-squared: 0.517, Adjusted R-squared: 0.4922
## F-statistic: 20.87 on 2 and 39 DF, p-value: 6.88e-07
##
##
## Value of test-statistic is: -3.788
##
## Critical values for test statistics:
## 1pct 5pct 10pct
## tau1 -2.62 -1.95 -1.61
According to the ADF test the series are integrated of order 1, or in other words have become stationary after 1 differentiation(s). The program differentiated the series until it found order where value of test-statistic: -3.7880011 is smaller than tau3 5pct: -1.95.
Simulation
ARMA(1,1)-GARCH(1,1)
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.